import Vue from 'vue'
import Vuex from 'vuex'
import request from '@/utils/request.js'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		token: '',
		hasLogin: false,
		userInfo:'',
		userCenterData:"",
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			//缓存用户登陆状态
			uni.setStorageSync('userInfo',provider);
		},
		//设置个人中心的数据
		setUserCenterData(state, provider){
			state.userCenterData = provider
			//缓存用户个人信息
			uni.setStorageSync('userCenterData',provider)
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			state.userCenterData = {};
			uni.removeStorage({key: 'userInfo'});
			uni.removeStorage({key: 'userCenterData'});
			uni.removeStorage({key: 'sld_login_time'});
			
		},
	}
})

export default store